/*******************************************************************************************
	map.cpp				MAP CLASS


********************************************************************************************/
#include "main.h"


/***********************************************************************
Loads a map into memory
***********************************************************************/
int Map::loadmap(char *name)
{
	infile.open(name, ios::in);
	
	pacnum = 0;
	numenemy = 0;
	int loop;
	//load tiles into layers
	for(loop = 0; loop < SIZEY; loop++) 
	{
		for(int loop2 = 0; loop2 < SIZEX; loop2++)
		{
			infile >> tiles[loop][loop2];

			x[loop][loop2] = (loop2*B_SIZE)-((float)W_WIDTH/2);
			y[loop][loop2] = ((W_HEIGHT-B_SIZE)-(loop*B_SIZE))-((float)W_HEIGHT/2);;
			
			if(tiles[loop][loop2] == PAC)  //get the pacs
				pacnum++;

			if(tiles[loop][loop2] == PACHEAD) //check for pachead
			{
				//initialize pachead
				pachead.x = (GLfloat)x[loop][loop2];
				pachead.y = (GLfloat)y[loop][loop2];
				pachead.posx = loop2;
				pachead.posy = loop;
				pachead.initposx = loop2;
				pachead.initposy = loop;
				pachead.direction = RIGHT;
				pachead.state = NORM;
				pachead.speed = 2*scale;
				pachead.health = 100;
				pachead.powertimer = 0;
				tiles[loop][loop2] = FLOOR;
				pachead.count1 = false;
				pachead.count2 = false;
			
			}
			
			///////////////////////////////////
			//check for enemies and initialize
			///////////////////////////////////
			if( (tiles[loop][loop2] == ATTACK ||tiles[loop][loop2] == FEAR 
				|| tiles[loop][loop2] == GUARD||tiles[loop][loop2] == RACER 
				|| tiles[loop][loop2] == TRACER) && numenemy < MAXENEMY)
			{
				switch(tiles[loop][loop2])
				{
				case ATTACK: enemies[numenemy] = new Attack();enemies[numenemy]->id = ATCK;break;
				case FEAR: enemies[numenemy] = new Fear();enemies[numenemy]->id = FR;break;
				case GUARD: enemies[numenemy] = new Guard();enemies[numenemy]->id = GRD;break;
				case TRACER: enemies[numenemy] = new Tracer();enemies[numenemy]->id = TRCR;break;
				case RACER: enemies[numenemy] = new Racer();enemies[numenemy]->id = RCR;break;
				};

				enemies[numenemy]->x = (GLfloat)x[loop][loop2];
				enemies[numenemy]->y = (GLfloat)y[loop][loop2];
				enemies[numenemy]->posx = loop2;
				enemies[numenemy]->posy = loop;
				enemies[numenemy]->direction = RIGHT;
				enemies[numenemy]->state = NORM;
				enemies[numenemy]->speed = 1*scale;
				enemies[numenemy]->initposx = loop2;
				enemies[numenemy]->initposy = loop;
				enemies[numenemy]->hit = false;

				tiles[loop][loop2] = FLOOR;

				numenemy++;
			}

				
		}
	}

	//////////////////////////////////
	//2nd layer map for special tiles
	//////////////////////////////////
	for(loop = 0; loop < SIZEY; loop++) 
	{
		for(int loop2 = 0; loop2 < SIZEX; loop2++)
		{
			infile >> special[loop][loop2];
		}
	}
	
	infile.close();

	info.mapintro();

	return 0;
}

class VEC3{
public:
	GLfloat x;
	GLfloat y;
	GLfloat z;

	VEC3 operator +(const VEC3 &other){
		VEC3 result = *this;
		result.x += other.x;
		result.y += other.y;
		result.z += other.z;
		return result;
	}

	VEC3 operator *(const float mult){
		VEC3 result = *this;
		result.x *= mult;
		result.y *= mult;
		result.z *= mult;
		return result;
	}
};

/***********************************************************************
Draws the map to the screen
***********************************************************************/
void Map::drawmap()
{
	GLfloat LightAmbient[]= { 0.0f, 0.0f, 0.0f, 1.0f };
	GLfloat LightDiffuse[]= { 0.0f, 0.0f, 0.0f, 1.0f };
	GLfloat LightPosition[]= { 0.0f, 0.0f, 12.0f, 1.0f };
	
	int lights[] = {GL_LIGHT1,GL_LIGHT2,GL_LIGHT3,GL_LIGHT4,GL_LIGHT5,GL_LIGHT6};
	
	for(int i = 0; i < 6; i++)
	{
		glDisable(lights[i]);
	}
	int light = 0;
	
	float dim = 0.0f;
	if(((framecount/10)%2) == 0)
	{
		dim = 0.2f;
	}
	
	for(int Y = 0; Y < SIZEY; Y++)
	{
		for(int X = 0; X < SIZEX; X++)
		{
			if(tiles[Y][X] == POWER)
			{
				if(light < 6)
					{
						LightPosition[0] = (GLfloat)x[Y][X];
						LightPosition[1] = (GLfloat)y[Y][X];
						
						LightDiffuse[0] = 1.0f-dim;
						LightDiffuse[1] = 0.0f;
						LightDiffuse[2] = 0.1f;

						glLightfv(lights[light], GL_AMBIENT, LightAmbient);	
						glLightfv(lights[light], GL_DIFFUSE, LightDiffuse);
						glLightfv(lights[light], GL_POSITION,LightPosition);
						glEnable(lights[light]);
						light++;
					}
			}
			if(tiles[Y][X] == SPEED)
			{
				if(light < 6)
					{
						LightPosition[0] = (GLfloat)x[Y][X];
						LightPosition[1] = (GLfloat)y[Y][X];
						
						LightDiffuse[0] = 1.0f-dim;
						LightDiffuse[1] = 1.0f-dim;
						LightDiffuse[2] = 0.1f;

						glLightfv(lights[light], GL_AMBIENT, LightAmbient);	
						glLightfv(lights[light], GL_DIFFUSE, LightDiffuse);
						glLightfv(lights[light], GL_POSITION,LightPosition);
						glEnable(lights[light]);
						light++;
					}
			}
			if(tiles[Y][X] == INVIS)
			{
				if(light < 6)
					{
						LightPosition[0] = (GLfloat)x[Y][X];
						LightPosition[1] = (GLfloat)y[Y][X];
						
						LightDiffuse[0] = 1.0f-dim;
						LightDiffuse[1] = 1.0f-dim;
						LightDiffuse[2] = 1.0f-dim;

						glLightfv(lights[light], GL_AMBIENT, LightAmbient);	
						glLightfv(lights[light], GL_DIFFUSE, LightDiffuse);
						glLightfv(lights[light], GL_POSITION,LightPosition);
						glEnable(lights[light]);
						light++;
					}
			}
		}
	}



	for(int index = 0; index < SIZEY; index++)
	{
		for(int loop = 0; loop < SIZEX; loop++)
		{
			if(tiles[index][loop] != '0')
			{
				if(tiles[index][loop] == WALL)
				{
					int color;

					//if(difficulty < 3)
						color = pachead.level%5;
					//else
					//	color = rand()%5;
						
						switch(color)
						{
							case 4: glColor3f(1.0f,0.0f,1.0f);break; //purple
							case 3:break;
							case 2: glColor3f(0.0f,1.0f,0.4f);break;//green
							case 1: glColor3f(0.0f,0.5f,1.0f);break;//blue
							case 0: glColor3f(0.0f,0.92f,0.9f);break;//teal
						};

				}
				if(tiles[index][loop] == PAC)
				{

					int color;

					if(difficulty < 3)
						color = pachead.level%5;
					else
						color = rand()%5;

					switch(color)
					{
					case 3: glColor3f(1.0f,0.0f,1.0f);break; //purple
					case 0:glColor3f(1.0f,0.0f,1.0f);break;//purple
					case 1: glColor3f(0.0f,1.0f,0.4f);break;//green///
					case 2: glColor3f(0.0f,0.5f,1.0f);break;//blue
					case 4: glColor3f(0.0f,0.92f,0.9f);break;//teal///
					};
				}

			
			switch(tiles[index][loop])
			{
			case WALL:
				{
					glBindTexture(GL_TEXTURE_2D, maptiles[0][0]);
					glDisable(GL_BLEND);

					glBegin(GL_QUADS); //draw the tiles

				//right
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  10.0f);
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  10.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Top Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  0.0f);	// Top Left Of The Texture and Quad
				
				glEnd();
				glBegin(GL_QUADS); //draw the tiles
				//left
				glVertex3f( (GLfloat)x[index][loop], (GLfloat)y[index][loop],  10.0f);
				glVertex3f( (GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  10.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Top Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop], (GLfloat)y[index][loop],  0.0f);	// Top Left Of The Texture and Quad
				
				glEnd();
				glBegin(GL_QUADS); //draw the tiles
				//down
				glVertex3f((GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  0.0f);	// Bottom Left Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop], (GLfloat)y[index][loop],  0.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop],  (GLfloat)y[index][loop],  10.0f);	// Top Right Of The Texture and Quad
				glVertex3f((GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop],  10.0f);	// Top Left Of The Texture and Quad
				
				glEnd();
				glBegin(GL_QUADS); //draw the tiles
				//up
				glVertex3f((GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Bottom Left Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop], (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  10.0f);	// Top Right Of The Texture and Quad
				glVertex3f((GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  10.0f);	// Top Left Of The Texture and Quad
				
				glEnd();

				glBegin(GL_QUADS); //draw the tiles
				//bottom
				glVertex3f((GLfloat)x[index][loop], (GLfloat)y[index][loop],  0.0f);
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  0.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Top Right Of The Texture and Quad
				glVertex3f((GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  0.0f);
				
				glEnd();
				glBegin(GL_QUADS); //draw the tiles
			//top
				glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)x[index][loop], (GLfloat)y[index][loop],  10.0f);	// Bottom Left Of The Texture and Quad
				glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  10.0f);	// Bottom Right Of The Texture and Quad
				glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  10.0f);	// Top Right Of The Texture and Quad
				glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  10.0f);	// Top Left Of The Texture and Quad
			glEnd();

					glColor3f(WHITE);
					glEnable(GL_BLEND);	
					continue;
					break;
				}
			case SWITCH:
				{
					glBindTexture(GL_TEXTURE_2D, maptiles[1][0]);
					glDisable(GL_BLEND);

					glBegin(GL_QUADS); //draw the tiles

				
						//right
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  4.0f);
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  4.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Top Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  0.0f);	// Top Left Of The Texture and Quad
				
				glEnd();
				glBegin(GL_QUADS); //draw the tiles
				//left
				glVertex3f( (GLfloat)x[index][loop], (GLfloat)y[index][loop],  4.0f);
				glVertex3f( (GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  4.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Top Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop], (GLfloat)y[index][loop],  0.0f);	// Top Left Of The Texture and Quad
				
				glEnd();
				glBegin(GL_QUADS); //draw the tiles
				//down
				glVertex3f((GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  0.0f);	// Bottom Left Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop], (GLfloat)y[index][loop],  0.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop],  (GLfloat)y[index][loop],  4.0f);	// Top Right Of The Texture and Quad
				glVertex3f((GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop],  4.0f);	// Top Left Of The Texture and Quad
				
				glEnd();
				glBegin(GL_QUADS); //draw the tiles
				//up
				glVertex3f((GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Bottom Left Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop], (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  4.0f);	// Top Right Of The Texture and Quad
				glVertex3f((GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  4.0f);	// Top Left Of The Texture and Quad
				
				glEnd();

				glBegin(GL_QUADS); //draw the tiles
				//bottom
				glVertex3f((GLfloat)x[index][loop], (GLfloat)y[index][loop],  0.0f);
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  0.0f);	// Bottom Right Of The Texture and Quad
				glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Top Right Of The Texture and Quad
				glVertex3f((GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  0.0f);
				
				glEnd();
				glBegin(GL_QUADS); //draw the tiles
			//top
				glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)x[index][loop], (GLfloat)y[index][loop],  4.0f);	// Bottom Left Of The Texture and Quad
				glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  4.0f);	// Bottom Right Of The Texture and Quad
				glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  4.0f);	// Top Right Of The Texture and Quad
				glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  4.0f);	// Top Left Of The Texture and Quad
				

					glEnd();
					glColor3f(WHITE);
					glEnable(GL_BLEND);	
					continue;
					break;
				}
			case SWALL:
				{
					glDisable(GL_TEXTURE_2D);
					
					GLUquadric * swall = gluNewQuadric();
					//gluQuadricTexture(swall, true);
					//glBindTexture(GL_TEXTURE_2D, maptiles[2][0]);
					
					glPushMatrix();
					
					int slices = 6;
					int stacks = 6;
					int loops = 6;

					glTranslated(x[index][loop]+9, y[index][loop]+9, 0);
					gluCylinder(swall, 5, 5, 10, slices, stacks);
					gluDisk(swall, 0, 5, slices, loops);
					glTranslated(0, 0, 10);
					gluDisk(swall, 0, 5, slices, loops);
					glTranslated(0, 0, -10);

					glTranslated(15, 3, 0);
					gluCylinder(swall, 4, 4, 10, slices, stacks);
					gluDisk(swall, 0, 4, slices, loops);
					glTranslated(0, 0, 10);
					gluDisk(swall, 0, 4, slices, loops);
					glTranslated(0, 0, -10);

					glTranslated(-8, 4, 0);
					gluCylinder(swall, 2, 2, 10, slices, stacks);
					gluDisk(swall, 0, 2, slices, loops);
					glTranslated(0, 0, 10);
					gluDisk(swall, 0, 2, slices, loops);
					glTranslated(0, 0, -10);


					glTranslated(-5, 8, 0);
					gluCylinder(swall, 5, 5, 10, slices, stacks);
					gluDisk(swall, 0, 5, slices, loops);
					glTranslated(0, 0, 10);
					gluDisk(swall, 0, 5, slices, loops);
					glTranslated(0, 0, -10);

					glTranslated(11, -2, 0);
					gluCylinder(swall, 3, 3, 10, slices, stacks);
					gluDisk(swall, 0, 3, slices, loops);
					glTranslated(0, 0, 10);
					gluDisk(swall, 0, 3, slices, loops);
					glTranslated(0, 0, -10);

					glPopMatrix();
					
					gluDeleteQuadric(swall);

					glEnable(GL_TEXTURE_2D);
					continue;
				}
			case SWALLD:
				{
					glDisable(GL_TEXTURE_2D);
					
					GLUquadric * swall = gluNewQuadric();
					//gluQuadricTexture(swall, true);
					//glBindTexture(GL_TEXTURE_2D, maptiles[2][0]);
					
					glPushMatrix();

					glColor3f(.5, .5, .5);

					int slices = 6;
					int stacks = 6;
					int loops = 6;

					glTranslated(x[index][loop]+9, y[index][loop]+9, 0);
					gluCylinder(swall, 5, 5, 1, slices, stacks);
					gluDisk(swall, 1, 5, slices, loops);

					glTranslated(15, 3, 0);
					gluCylinder(swall, 4, 4, 1, slices, stacks);
					gluDisk(swall, 1, 4, slices, loops);

					glTranslated(-8, 4, 0);
					gluCylinder(swall, 2, 2, 1, slices, stacks);
					gluDisk(swall, 1, 2, slices, loops);

					glTranslated(-5, 8, 0);
					gluCylinder(swall, 5, 5, 1, slices, stacks);
					gluDisk(swall, 1, 5, slices, loops);

					glTranslated(11, -2, 0);
					gluCylinder(swall, 3, 3, 1, slices, stacks);
					gluDisk(swall, 1, 3, slices, loops);

					glPopMatrix();
					
					gluDeleteQuadric(swall);

					glEnable(GL_TEXTURE_2D);
					continue;
				}
			case WARP:
				{
					glBindTexture(GL_TEXTURE_2D, maptiles[4][(framecount/10)%2]);
					break;
				}
			case PAC:
				{
					GLUquadric * sphere = gluNewQuadric();
					gluQuadricTexture(sphere, true);
					glBindTexture(GL_TEXTURE_2D, maptiles[5][0]);
					
					int slices = 10;
					int stacks = 10;

					glPushMatrix();
					glTranslated(x[index][loop]+B_SIZE/2, y[index][loop]+B_SIZE/2, 5);
					gluSphere(sphere, 5, slices, stacks);
					glPopMatrix();
					
					gluDeleteQuadric(sphere);
					continue;
				}
			case POWER:
				{
					GLUquadric * sphere = gluNewQuadric();
					gluQuadricTexture(sphere, true);
					glBindTexture(GL_TEXTURE_2D, maptiles[6][(framecount/10)%2]);
					
					glPushMatrix();
					glTranslated(x[index][loop]+B_SIZE/2, y[index][loop]+B_SIZE/2, 5);	
					gluSphere(sphere, 8, 10, 10);
					glPopMatrix();
					
					gluDeleteQuadric(sphere);
					continue;
				}
			case SPEED:
				{
					GLUquadric * sphere = gluNewQuadric();
					gluQuadricTexture(sphere, true);
					glBindTexture(GL_TEXTURE_2D, maptiles[7][(framecount/10)%2]);
					
					glPushMatrix();
					glTranslated(x[index][loop]+B_SIZE/2, y[index][loop]+B_SIZE/2, 5);
					if((framecount/10)%2 == 0){
						gluSphere(sphere, 3, 10, 10);
					}else{
						gluSphere(sphere, 4, 10, 10);
					}
					glPopMatrix();
					
					gluDeleteQuadric(sphere);
					continue;
				}
			case INVIS:
				{
					GLUquadric * sphere = gluNewQuadric();
					gluQuadricTexture(sphere, true);
					glBindTexture(GL_TEXTURE_2D, maptiles[8][(framecount/10)%2]);
					
					glPushMatrix();
					glTranslated(x[index][loop]+B_SIZE/2, y[index][loop]+B_SIZE/2, 5);
					if((framecount/10)%2 == 0){
						gluSphere(sphere, 6, 10, 10);
					}else{
						gluSphere(sphere, 7, 10, 10);
					}
					glPopMatrix();
					
					gluDeleteQuadric(sphere);
					continue;
				}
			case GHOST:
				{
					GLUquadric * sphere = gluNewQuadric();
					gluQuadricTexture(sphere, true);
					glBindTexture(GL_TEXTURE_2D, maptiles[9][(framecount/10)%2]);
					
					glPushMatrix();
					glTranslated(x[index][loop]+B_SIZE/2, y[index][loop]+B_SIZE/2, 5);
					if((framecount/10)%2 == 0){
						gluSphere(sphere, 3, 10, 10);
					}else{
						gluSphere(sphere, 4, 10, 10);
					}
					glPopMatrix();
					
					gluDeleteQuadric(sphere);
					continue;
				}
			};

			glBegin(GL_QUADS); //draw the tiles

				
				glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)x[index][loop], (GLfloat)y[index][loop],  0.0f);	// Bottom Left Of The Texture and Quad
				glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)x[index][loop]+B_SIZE, (GLfloat)y[index][loop],  0.0f);	// Bottom Right Of The Texture and Quad
				glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)x[index][loop]+B_SIZE,  (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Top Right Of The Texture and Quad
				glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)x[index][loop],  (GLfloat)y[index][loop]+B_SIZE,  0.0f);	// Top Left Of The Texture and Quad
				

			glEnd();
			glColor3f(WHITE);
			glEnable(GL_BLEND);	

			}
		}
	}
	glEnable(GL_BLEND);
}


/***********************************************************************
Loads the tile graphics into memory
***********************************************************************/
void Map::loadmaptiles()
{
	
	char *tilefiles[] =
	{ 
		"sprite/wall.bmp",
		"sprite/switch.bmp",
		"sprite/swall.bmp",
		"sprite/swalld.bmp",
		"sprite/warp.bmp",
		"sprite/pac.bmp",
		"sprite/power.bmp",
		"sprite/speed.bmp",
		"sprite/invis.bmp",
		"sprite/ghost.bmp",
		"sprite/power2.bmp",
		"sprite/speed2.bmp",
		"sprite/invis2.bmp",
		"sprite/ghost2.bmp",
		"sprite/warp2.bmp"
	};			

	for(int index = 0; index < TILENUM; index++)
	{
		maptiles[index][0] = LoadGLTextures(tilefiles[index]);

	}
	maptiles[6][1] = LoadGLTextures(tilefiles[10]);
	maptiles[7][1] = LoadGLTextures(tilefiles[11]);
	maptiles[8][1] = LoadGLTextures(tilefiles[12]);
	maptiles[9][1] = LoadGLTextures(tilefiles[13]);
	maptiles[4][1] = LoadGLTextures(tilefiles[14]);


}
